// 1.引入http模块
const http = require('http');
// 导入url模块
const url = require('url');

// 2.创建服务对象
const server = http.createServer((req, res) => {
  // 2.解析url
  const url = req.url;
  let res = url.parse(url, true);
  console.log(res);
  // 路径
  let pathname = res.pathname;
  // 查询字符串
  let query = res.query;
  console.log(pathname, query);
  res.end('hello HTTP');
});

// 3.监听端口，启动服务
server.listen(9000, () => {
  // 服务启动成功后的回调
  console.log('服务器启动成功');
});